//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of your Microsoft Windows CE
// Source Alliance Program license form.  If you did not accept the terms of
// such a license, you are not authorized to use this source code.
//
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2003 Intrinsyc Europe Ltd.
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2004 Siemens AG
//
// Version: 1.1.2.5
// Date:    11. Jan. 2006
//////////////////////////////////////////////////////////////////////////////
//
//
// (C) Copyright 2007 Marvell International Ltd.
//  All Rights Reserved
//

#include "precomp.h"
#include "resource.h"
#include <devnotify.h>
#include "rilversion.h"

#include "args.h"
#include "ioctl_cfg.h"

#include <serhw.h>
#include <16550.h>

//
// Globals
//
CRilEventLog g_RilLog;
CRITICAL_SECTION g_csClosing;
HANDLE g_hCriticalErrorEvent; // = NULL;
HANDLE g_hDriverPresentEvent; // = NULL;
HANDLE g_hNewDialOrHangupEvent; // = NULL;
HANDLE g_hMuxChannelInitEvent;  // = NULL;
DWORD g_dwReadyState;
DWORD g_dwRegStatus;
DWORD g_dwGPRSRegStatus;
extern CRITICAL_SECTION g_CallInfoSection;
extern CRITICAL_SECTION g_PPLMNBufferSection;
#ifdef RIL_LAST_ERROR
DWORD g_dwLastError;            // = 0;
#endif

extern VOID RIL_PrintIoCtrlCode(DWORD dwCode);

//
// Stubs for unsupported RILDrv_ functions
//
#define UNSUPPORTED(n, m) \
HRESULT n m \
{ \
    TBD_FUNCTION(n); \
    TBD_OUTPUT(TBDCT_INFO, TBDOL_ERROR, TEXT(#n) TEXT(" : E_NOTIMPL")); \
    return E_NOTIMPL; \
}


UNSUPPORTED(RILDrv_SetDTMFMonitoring, (DWORD, BOOL));
UNSUPPORTED(RILDrv_GetAudioDevices, (DWORD));
UNSUPPORTED(RILDrv_FetchSimToolkitCmd, (DWORD));
UNSUPPORTED(RILDrv_SetHideConnectedIdStatus, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetCCBSStatus, (DWORD, DWORD));
UNSUPPORTED(RILDrv_ClearCCBSRegistration, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetSystemTime, (DWORD));
UNSUPPORTED(RILDrv_GetPacketByteCount, (DWORD));
UNSUPPORTED(RILDrv_ResetPacketByteCount, (DWORD));
UNSUPPORTED(RILDrv_SendFlash, (DWORD, RILADDRESS));
UNSUPPORTED(RILDrv_GetRoamingMode, (DWORD));
UNSUPPORTED(RILDrv_SetRoamingMode, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetPreferredPrivacyMode, (DWORD));
UNSUPPORTED(RILDrv_SetPreferredPrivacyMode, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetCurrentPrivacyStatus, (DWORD));

// These HSCSC and data options are not supported by Siemens modules.
UNSUPPORTED(RILDrv_GetHSCSDOptions, (DWORD));
UNSUPPORTED(RILDrv_SetHSCSDOptions, (DWORD, RILHSCSDINFO *));
UNSUPPORTED(RILDrv_GetHSCSDCallSettings, (DWORD));
UNSUPPORTED(RILDrv_GetDataCompression, (DWORD));
UNSUPPORTED(RILDrv_SetDataCompression, (DWORD, RILDATACOMPINFO *));
UNSUPPORTED(RILDrv_GetErrorCorrection, (DWORD));
UNSUPPORTED(RILDrv_SetErrorCorrection, (DWORD, RILERRORCORRECTIONINFO *));


#ifdef SIEMENS_MAGNETO
UNSUPPORTED(RILDrv_GetCurrentLocationStatus, (DWORD));
UNSUPPORTED(RILDrv_GetCurrentRoamingStatus, (DWORD));
UNSUPPORTED(RILDrv_SendAKey, (DWORD, LPCSTR));
UNSUPPORTED(RILDrv_GetATR, (DWORD));
#else
UNSUPPORTED(RILDrv_SendAKey, (DWORD));
#endif

extern RHA_FUNCTION_LIST RHAFunctionList;

HANDLE hInstance;

//
// DLL entry point
//
BOOL WINAPI DllMain(HANDLE hinstDll, DWORD dwReason, LPVOID lpReserved)
{
    hInstance = hinstDll;

    if (DLL_PROCESS_ATTACH == dwReason)
    {
        g_RilLog.Register();
        TBD_INITIALIZE();
        TBD_ENABLE_CLASS(TBDCT_ALL_FUNCTIONS, TRUE);
        TBD_ENABLE_CLASS(TBDCT_INFO, TRUE);
        TBD_ENABLE_CLASS(TBDCT_READ, FALSE);
        TBD_SET_LEVEL(TBDOL_TRACE);
        TBD_IMPORT_REGISTRY_SETTINGS();
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL - DllMain : DLL_PROCESS_ATTACH"));
    }
    else if (DLL_PROCESS_DETACH == dwReason)
    {
        g_RilLog.Unregister();
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL - DllMain : DLL_PROCESS_DETACH"));
        TBD_DEINITIALIZE();
    }
    return TRUE;
}

#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
CRilHandle * g_pDeviceAllowDriverRemovalTesting = NULL;
#define DRIVERCOOKIE_FROM_RILHANDLE(pDevice)    (DWORD)(g_pDeviceAllowDriverRemovalTesting = pDevice)
#define RILHANDLE_FROM_DRIVERCOOKIE(dwData)     (g_pDeviceAllowDriverRemovalTesting)
#else
#define DRIVERCOOKIE_FROM_RILHANDLE(pDevice)    (DWORD)pDevice;
#define RILHANDLE_FROM_DRIVERCOOKIE(dwData)     (CRilHandle*)dwData;
#endif


//
// RIL driver initialization
//
DWORD RIL_Init(DWORD dwInfo)
{
    TBD_FUNCTION(RIL_Init);
    TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_Init : params: dwInfo = %d"), dwInfo);

    CRilHandle* pDevice = NULL;
    DWORD dwRet = 0;
    BSP_ARGS BspArgs;
    DWORD dwSize;

    /* Check EBOOT Configuration  */
    if (!KernelIoControl(IOCTL_GET_BSP_ARGS, NULL, 0, &BspArgs, sizeof(BspArgs), &dwSize))
    {
        RILRetailTrace((TEXT("RIL_Init Failed in KernelIoControl(IOCTL_GET_BSP_ARGS)\n")));            
        return dwRet;
    }

    if (!(BspArgs.FFUARTUsage&BSP_ARGS_FFUART_RIL))
    {
        RILRetailTrace((TEXT("RIL_Init: FFUART had not been configured for RIL driver, RIL will not be load\n")));            
        return dwRet;
    }
    
    // Initialize globals
    InitializeCriticalSection(&g_csClosing);
    InitializeCriticalSection(&g_CallInfoSection);
    InitializeCriticalSection(&g_PPLMNBufferSection);
    g_hCriticalErrorEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_hCriticalErrorEvent)
    {
        goto Error;
    }

    g_hDriverPresentEvent = CreateEvent(NULL, TRUE, FALSE, RILDRIVERPRESENT_EVENT);
    if (!g_hDriverPresentEvent)
    {
        goto Error;
    }

    g_hNewDialOrHangupEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_hNewDialOrHangupEvent)
    {
        goto Error;
    }

    g_hMuxChannelInitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_hMuxChannelInitEvent)
    {
        goto Error;
    }


    // Allocate a device handle
    pDevice = new CRilHandle;
    if(RHAFunctionList.pfnRHA_RadioPwrOn == NULL || RHAFunctionList.pfnRHA_RadioPwrOff == NULL || RHAFunctionList.pfnRHA_IsRadioPwrOn == NULL ||
        RHAFunctionList.pfnRHA_ActivateVoicePath == NULL || RHAFunctionList.pfnRHA_DeactivateVoicePath == NULL || RHAFunctionList.pfnRHA_AdjustTxVolume == NULL ||
        RHAFunctionList.pfnRHA_AdjustRxVolume == NULL || RHAFunctionList.pfnRHA_GetRHAVersion == NULL)
    {
        goto Error;
    }

    if (!pDevice || !pDevice->StartInit())
    {
        goto Error;
    }

    g_ComManager.Init(pDevice);
    g_PowerManager.Init(pDevice);

    CPowerCmd *pTmpCmd = new CPowerCmd(MODEMSTATE_SIEMENS_POWERON, NULL, D0, D0, FALSE, FALSE);
    if (!g_PowerManager.TurnOnModule(pTmpCmd, FALSE))
    {
        RILRetailTrace((TEXT("RIL_Init: Current g_PowerManager.TurnOnModule Failed!\n")));
        goto Error;
    }

    g_PowerManager.InitPowerStateForModuleTurnOn();

    // Driver has started successfully, so set
    // the event that says RIL driver is up.
    SetEvent(g_hDriverPresentEvent);
    g_RilLog.LogEvent(RILLOG_ZONE_PRESENCE, RILLOG_EVENT_RADIOPRESENT);
    pDevice->GeneralInitDone(TRUE);
    RILRetailTrace((TEXT("RIL_Init: GeneralInitDone Completed !\n")));
        
    dwRet = DRIVERCOOKIE_FROM_RILHANDLE(pDevice);
    
    Error:
    if (!dwRet)
    {
        TBD_OUTPUT(TBDCT_INFO, TBDOL_ERROR, TEXT("RIL_Init : RIL failed to initialize"));

        g_RilLog.LogEvent(RILLOG_ZONE_ERROR, RILLOG_EVENT_DRVINITFAILED);

        if (pTmpCmd)
        {

            delete pTmpCmd;
            pTmpCmd = NULL;
        }

        if (pDevice)
        {

            delete pDevice;
            pDevice = NULL;
        }
        
        if (g_hDriverPresentEvent)
        {
            (void)CloseHandle(g_hDriverPresentEvent);
            g_hDriverPresentEvent = NULL;
        }
        if (g_hCriticalErrorEvent)
        {
            (void)CloseHandle(g_hCriticalErrorEvent);
            g_hCriticalErrorEvent = NULL;
        }

        if (g_hMuxChannelInitEvent)
        {
            (void)CloseHandle(g_hMuxChannelInitEvent);
            g_hMuxChannelInitEvent = NULL;
        }


        DeleteCriticalSection(&g_CallInfoSection);
        DeleteCriticalSection(&g_PPLMNBufferSection);
        DeleteCriticalSection(&g_csClosing);
    }

    TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("-RIL_Init()"));
    return dwRet;
}

//
// Driver de-initialization
//
BOOL RIL_Deinit(DWORD dwData)
{
    TBD_FUNCTION(RIL_Deinit);
    TBD_ASSERT(dwData != 0);

    CRilHandle* pDevice = RILHANDLE_FROM_DRIVERCOOKIE(dwData);
    BOOL fRet = FALSE;

    // Driver is going away. Clear event that
    // says RIL driver is up.
    if (g_hDriverPresentEvent)
    {
        ResetEvent(g_hDriverPresentEvent);
        (void)CloseHandle(g_hDriverPresentEvent);
        g_hDriverPresentEvent = NULL;
        g_RilLog.LogEvent(RILLOG_ZONE_PRESENCE, RILLOG_EVENT_RADIOREMOVED);
    }

    g_PowerManager.Deinit();
    g_ComManager.Deinit();

    if (!pDevice)
    {
        goto Error;
    }
    delete pDevice;

    if (g_hCriticalErrorEvent)
    {
        (void)CloseHandle(g_hCriticalErrorEvent);
        g_hCriticalErrorEvent = NULL;
    }
    DeleteCriticalSection(&g_CallInfoSection);
    DeleteCriticalSection(&g_PPLMNBufferSection);
    DeleteCriticalSection(&g_csClosing);
    fRet = TRUE;

    Error:
    return fRet;
}


//
// Open a driver instance
//
DWORD RIL_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
    //TBD_FUNCTION(RIL_Open);
    TBD_ASSERT(dwData != 0);

    CRilInstanceHandle* pHandle = NULL;
    CRilHandle* pDevice = RILHANDLE_FROM_DRIVERCOOKIE(dwData);
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (!g_pDeviceAllowDriverRemovalTesting)
    {
        return 0x4321;
    }
#endif
    DWORD dwRet = 0;

    // Wait until the COM port is initialized
    if (!pDevice /* || !pDevice->WaitForInit(MAX_DRIVERINIT_TIME) */ )
    {
        goto Error;
    }

    pHandle = new CRilInstanceHandle;
    if (!pHandle || !pHandle->Init(pDevice))
    {
        goto Error;
    }

    // Insert new handle into the handle list
    if (!pDevice->AddToList(pHandle))
    {
        goto Error;
    }

    dwRet = (DWORD)pHandle;

#ifdef TBD_DEBUG
    //RILRetailTrace((TEXT("RIL_Open: Current RIL Instance Nums = %d \n"), pDevice->GetRILInstanceNums()));
#endif
    
    Error:
    if (!dwRet)
    {
        delete pHandle;
    }
    return dwRet;
}


//
// Close a driver instance
//
BOOL RIL_Close(DWORD dwOpenData)
{
    //TBD_FUNCTION(RIL_Close);
    TBD_ASSERT(dwOpenData != 0);

#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (dwOpenData == 0x4321 || !g_pDeviceAllowDriverRemovalTesting)
    {
        return TRUE;
    }
#endif
    CRilInstanceHandle* pHandle = (CRilInstanceHandle*)dwOpenData;

    if (!pHandle)
    {
        return FALSE;
    }

    SYNCBLOCK(g_csClosing);

    // Make sure no commands refer to this handle
    pHandle->GetCmdList()->Enum(ClearCmdHandle, 0);

    TBD_ASSERT(pHandle->GetDevice() != 0);

    // Remove the handle from the handle list
    if (!pHandle->GetDevice()->RemoveFromList(pHandle))
    {
        return FALSE;
    }
    
    delete pHandle;
    return TRUE;
}



//
// Emulate serial read
//
DWORD RIL_Read(DWORD dwOpenData, LPVOID pBuf, DWORD len)
{
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (g_pDeviceAllowDriverRemovalTesting)
    {
        RIL_Close(dwOpenData);
        RIL_Deinit(1);
        g_pDeviceAllowDriverRemovalTesting = NULL;
    }
#endif
    return 0;
}


//
// Emulate serial write
//
DWORD RIL_Write(DWORD dwOpenData, LPCVOID pBuf, DWORD len)
{
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (!g_pDeviceAllowDriverRemovalTesting)
    {
        ASSERT(dwOpenData == 0x4321);
        RIL_Init(1);
    }
#endif
    return 0;
}


//
//
//
DWORD RIL_Seek(DWORD dwOpenData, long pos, DWORD type)
{
    return (DWORD)-1;
}


//
//
//
void RIL_PowerDown(DWORD dwData)
{
}


//
//
//
void RIL_PowerUp(DWORD dwData)
{
}


//
// Defines used in the switch below
//
#define CALLDRVAPI_PARAMS(PARAMSTYPE, APICall)              \
    {                                                       \
        PARAMSTYPE##* pParams = (##PARAMSTYPE##*)pBufIn;    \
        if (pBufIn && dwLenIn == sizeof(PARAMSTYPE)) {      \
            *phr = APICall;                                 \
            dwOutUsed = sizeof(HRESULT);                    \
            fRet = TRUE;                                    \
        }                                                   \
    }

#define CALLDRVAPI_VARPARAMS(PARAMSTYPE, APICall)           \
    {                                                       \
        PARAMSTYPE##* pParams = (##PARAMSTYPE##*)pBufIn;    \
        if (pBufIn && dwLenIn >= sizeof(PARAMSTYPE)) {      \
            *phr = APICall;                                 \
            dwOutUsed = sizeof(HRESULT);                    \
            fRet = TRUE;                                    \
        }                                                   \
    }

#define CALLDRVAPI_OPTVARPARAMS(PARAMSTYPE, APICall)        \
    {                                                       \
        PARAMSTYPE##* pParams = (##PARAMSTYPE##*)pBufIn;    \
        if (!pBufIn || dwLenIn >= sizeof(PARAMSTYPE)) {     \
            *phr = APICall;                                 \
            dwOutUsed = sizeof(HRESULT);                    \
            fRet = TRUE;                                    \
        }                                                   \
    }

#define CALLDRVAPI_ARRAY(ELEMTYPE, APICall)                 \
    {                                                       \
        ELEMTYPE##* pParams = (##ELEMTYPE##*)pBufIn;        \
        if (pBufIn) {                                       \
            *phr = APICall;                                 \
            dwOutUsed = sizeof(HRESULT);                    \
            fRet = TRUE;                                    \
        }                                                   \
    }

#define CALLDRVAPI(APIName)                                 \
    *phr = APIName(dwOpenData);                             \
    dwOutUsed = sizeof(HRESULT);                            \
    fRet = TRUE;


//
//
//
BOOL RIL_IOControl(DWORD dwOpenData, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut,
                   PDWORD pdwActualOut)
{
    //TBD_FUNCTION(RIL_IOControl);
    TBD_ASSERT(dwOpenData != 0);

    DWORD dwOutUsed = 0;
    BOOL fRet = FALSE;

#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (!g_pDeviceAllowDriverRemovalTesting)
    {
        ASSERT(!"RIL_IOControl should not be called after the driver has gone away");
        return FALSE;
    }
#endif

    CRilInstanceHandle* pHandle = (CRilInstanceHandle*)dwOpenData;
    if (!pHandle)
    {
        goto Error;
    }

#ifdef TBD_DEBUG
    RIL_PrintIoCtrlCode(dwCode);

    CRilHandle* pDbgRilDevice = pHandle->GetDevice();
    if (!pDbgRilDevice)
    {
        goto Error;
    }
    
    //RILRetailTrace((TEXT("RIL_IOControl: Current RIL Instance Nums = %d \n"), 
    //                pDbgRilDevice->GetRILInstanceNums()));

#endif


    switch (dwCode)
    {
#ifdef RIL_ENABLE_POWER_HANDLING 
        // Power managing interface
    case IOCTL_POWER_CAPABILITIES:
        if (pBufOut && pdwActualOut && (dwLenOut >= sizeof (POWER_CAPABILITIES))) {
          g_PowerManager.FillPowerCapsStruct((PPOWER_CAPABILITIES)pBufOut);
          *pdwActualOut = sizeof(POWER_CAPABILITIES);
          fRet = TRUE;
        } else {
          SetLastError(ERROR_INVALID_PARAMETER);
        }
        goto Error;
    case IOCTL_POWER_GET:
        if (pBufOut && pdwActualOut && (dwLenOut >= sizeof (CEDEVICE_POWER_STATE))) {
          *(PCEDEVICE_POWER_STATE)pBufOut = g_PowerManager.GetPowerState();
          *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
          fRet = TRUE;
        } else {
          SetLastError(ERROR_INVALID_PARAMETER);
        }
        goto Error;
    case IOCTL_POWER_SET:
        if (pBufOut && pdwActualOut && (dwLenOut >= sizeof (CEDEVICE_POWER_STATE))) {
          if (SUCCEEDED(RILDrv_SetPowerState(dwOpenData, *(PCEDEVICE_POWER_STATE)pBufOut))) {
            fRet = TRUE;
          }
          *(PCEDEVICE_POWER_STATE)pBufOut = g_PowerManager.GetPowerState();
          *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        } else {
          SetLastError(ERROR_INVALID_PARAMETER);
        }
        goto Error;
        // End of power managing interface
#endif // RIL_ENABLE_POWER_HANDLING

        // Handle the headset IOCTLs
    case IOCTL_CARKIT_ADD_NOTIFY_HWND:
        // Not Supported
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Add carkit notif - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;

    case IOCTL_CARKIT_REMOVE_NOTIFY_HWND:
        // Not Supported
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Remove carkit notif - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;

    case IOCTL_HEADSET_ADD_NOTIFY_HWND:
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Add headset notify - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;

    case IOCTL_HEADSET_REMOVE_NOTIFY_HWND:
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Remove headset notify - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;

    case IOCTL_SPEAKER_ADD_NOTIFY_HWND:
        // Not Supported
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Add speaker notif - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;

    case IOCTL_SPEAKER_REMOVE_NOTIFY_HWND:
        // Not Supported
        TBD_OUTPUT(TBDCT_INFO, TBDOL_INFORMATION, TEXT("RIL_IoControl: Remove speaker notif - not supported"));
        SetLastError (ERROR_NOT_SUPPORTED);
        goto Error;
    }

    if(SUCCEEDED(ValidateAPIPermission(TEXT("rilgsm"), TEXT("IOControl"), VAP_TRUST_CALLER)))  // Perform security check
    {

        switch (dwCode)
        {
        // CPM is ready for us to register with it
        case IOCTL_RIL_REGISTERWITHCPM:
            {
                CRilHandle* pRilDevice = pHandle->GetDevice();
                TBD_ASSERT(NULL != pRilDevice);
                fRet = pRilDevice->RegisterWithCPM();
            }
            break;

            // This handle will be used for an emergency call - it should be marked as preferred and RIL should be
            //    switched into "emergency mode"
        case IOCTL_RIL_EMERGENCYSTATUS:
            fRet = pHandle->MakePreferred();
            break;

            // Initialize notification delivery
        case IOCTL_RIL_INITNOTIFICATIONS:
            if (pBufIn)
            {
                fRet = pHandle->CreateNotificationQueue((LPCTSTR)pBufIn, pBufOut, dwLenOut, &dwOutUsed);
            }
            break;

            // Get next RIL notification
        case IOCTL_RIL_GETNEXTNOTIFICATION:
            {
                RILDRVNOTIFICATION* pResult = (RILDRVNOTIFICATION*)pBufOut;
                if (pBufOut && dwLenOut >= sizeof(RILDRVNOTIFICATION) &&
                    SUCCEEDED(RILDrv_GetNextNotification(dwOpenData, pResult)))
                {

                    dwOutUsed = pResult->cbSize;
                    fRet = TRUE;
                }
                break;
            }

            // RIL_GetSerialPortStatistics()
        case IOCTL_RIL_GETSERIALPORTSTATISTICS:
            {
                RILSERIALPORTSTATS* pResult = (RILSERIALPORTSTATS*)pBufOut;
                if (pBufOut && dwLenOut >= sizeof(RILSERIALPORTSTATS) &&
                    SUCCEEDED(RILDrv_GetSerialPortStatistics(dwOpenData, pResult)))
                {

                    dwOutUsed = sizeof(RILSERIALPORTSTATS);
                    fRet = TRUE;
                }
                break;
            }

            // RIL_GetDriverVersion()
        case IOCTL_RIL_GETDRIVERVERSION:
            {
                if (pBufOut && (dwLenOut >= sizeof(DWORD)))
                {
                    *((PDWORD)pBufOut) = (DWORD)RIL_VERSION_NUM;
                    dwOutUsed = sizeof(DWORD);
                    fRet = TRUE;
                }
                break;
            }

#ifdef RIL_LAST_ERROR
        case IOCTL_RIL_GETLASTERROR:
            {
                DWORD *pResult = (DWORD *)pBufOut;
                if (pBufOut && dwLenOut >= sizeof(DWORD))
                {
                    // Give them back the error
                    *pResult = g_dwLastError;
                    dwOutUsed = sizeof(DWORD);
                    fRet = TRUE;
                }
                break;
            }
            break;
#endif
        case IOCTL_PSL_NOTIFY:
            {
                pHandle->CancelNotifications();
                fRet = TRUE;
                break;
            }

#ifdef SIEMENS_MAGNETO
        case IOCTL_RIL_GETSERIALPORTHANDLEFROMCONTEXTID:
            {
                if (pBufIn && (dwLenIn >= sizeof(DWORD)))
                {
                    TCHAR* szPort = g_ComManager.GetPortName(g_ComManager.GetPortFromContextId(*((DWORD*)pBufIn)));
                    if (szPort)
                    {
                        if ((_tcslen(szPort) + 1) < dwLenOut)
                        {
                            _tcscpy((TCHAR*)pBufOut, szPort);
                            dwOutUsed = _tcslen((TCHAR*)pBufOut);
                            fRet = TRUE;
                        }
                    }
                }
                break;
            }
#endif // SIEMENS_MAGNETO

        // Other RIL_ APIs
        default:
            {
                HRESULT* phr = (HRESULT*)pBufOut;
                if (!pBufOut || dwLenOut < sizeof(HRESULT))
                {
                    goto Error;
                }

                // RILRetailTrace((TEXT("RilDrv: IOCTL-Function-Parameter: %d\r\n"), (dwCode >> 2) & 0xFFF));
                switch (dwCode)
                {
                // RIL_GetSubscriberNumbers()
                case IOCTL_RIL_GETSUBSCRIBERNUMBERS:
                    CALLDRVAPI(RILDrv_GetSubscriberNumbers);
                    break;

                    // RIL_GetOperatorList()
                case IOCTL_RIL_GETOPERATORLIST:
                    CALLDRVAPI(RILDrv_GetOperatorList);
                    break;

                    // RIL_GetPreferredOperatorList()
                case IOCTL_RIL_GETPREFERREDOPERATORLIST:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetPreferredOperatorList(dwOpenData, *pParams));
                    break;

                    // RIL_AddPreferredOperator()
                case IOCTL_RIL_ADDPREFERREDOPERATOR:
                    CALLDRVAPI_PARAMS(ADDPREFERREDOPERATOR_PARAMS, RILDrv_AddPreferredOperator(dwOpenData, \
                                                                                                            pParams->dwIndex, &pParams->ronOperatorNames));
                    break;

                    // RIL_RemovePreferredOperator()
                case IOCTL_RIL_REMOVEPREFERREDOPERATOR:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_RemovePreferredOperator(dwOpenData, *pParams));
                    break;

                    // RIL_GetCurrentOperator()
                case IOCTL_RIL_GETCURRENTOPERATOR:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetCurrentOperator(dwOpenData, *pParams));
                    break;
#ifndef X86_EMUL
                    // RIL_GetAllOperatorsList()
                case IOCTL_RIL_GETALLOPERATORSLIST:
                    CALLDRVAPI(RILDrv_GetAllOperatorsList);
                    break;
#endif
                    // RIL_RegisterOnNetwork()
                case IOCTL_RIL_REGISTERONNETWORK:
                    CALLDRVAPI_PARAMS(REGISTERONNETWORK_PARAMS, RILDrv_RegisterOnNetwork(dwOpenData, pParams->dwMode, \
                                                                                                      &pParams->ronOperatorNames));
                    break;
                case IOCTL_RIL_UNREGISTERFROMNETWORK:
                    CALLDRVAPI(RILDrv_UnregisterFromNetwork);
                    break;

                    // RIL_GetRegistrationStatus()
                case IOCTL_RIL_GETREGISTRATIONSTATUS:
                    CALLDRVAPI(RILDrv_GetRegistrationStatus);
                    break;

                    // RIL_GetCallerIdSettings()
                case IOCTL_RIL_GETCALLERIDSETTINGS:
                    CALLDRVAPI(RILDrv_GetCallerIdSettings);
                    break;

                    // RIL_SetCallerIdStatus()
                case IOCTL_RIL_SETCALLERIDSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetCallerIdStatus(dwOpenData, *pParams));
                    break;

                    // RIL_GetHideIdSettings()
                case IOCTL_RIL_GETHIDEIDSETTINGS:
                    CALLDRVAPI(RILDrv_GetHideIdSettings);
                    break;

                    // RIL_SetHideIdStatus()
                case IOCTL_RIL_SETHIDEIDSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetHideIdStatus(dwOpenData, *pParams));
                    break;

                    // RIL_GetDialedIdSettings()
                case IOCTL_RIL_GETDIALEDIDSETTINGS:
                    CALLDRVAPI(RILDrv_GetDialedIdSettings);
                    break;

                    // RIL_SetDialedIdStatus()
                case IOCTL_RIL_SETDIALEDIDSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetDialedIdStatus(dwOpenData, *pParams));
                    break;

                    // RIL_GetHideConnectedIdSettings()
                case IOCTL_RIL_GETHIDECONNECTEDIDSETTINGS:
                    CALLDRVAPI(RILDrv_GetHideConnectedIdSettings);
                    break;

                    // RIL_SetHideConnectedIdStatus()
                case IOCTL_RIL_SETHIDECONNECTEDIDSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetHideConnectedIdStatus(dwOpenData, *pParams));
                    break;

                    // RIL_GetClosedGroupSettings()
                case IOCTL_RIL_GETCLOSEDGROUPSETTINGS:
                    CALLDRVAPI(RILDrv_GetClosedGroupSettings);
                    break;

                    // RIL_SetClosedGroupSettings()
                case IOCTL_RIL_SETCLOSEDGROUPSETTINGS:
                    CALLDRVAPI_PARAMS(RILCLOSEDGROUPSETTINGS, RILDrv_SetClosedGroupSettings(dwOpenData, pParams));
                    break;

                    // RIL_GetCallForwardingSettings()
                case IOCTL_RIL_GETCALLFORWARDINGSETTINGS:
                    CALLDRVAPI_PARAMS(GETCALLFORWARDING_PARAMS, RILDrv_GetCallForwardingSettings(dwOpenData, pParams->dwReason, pParams->dwInfoClasses));
                    break;

                    // RIL_AddCallForwarding()
                case IOCTL_RIL_ADDCALLFORWARDING:
                    CALLDRVAPI_PARAMS(ADDCALLFORWARDING_PARAMS, RILDrv_AddCallForwarding(dwOpenData, pParams->dwReason, \
                                                                                                      &pParams->rcfsSettings));
                    break;

                    // RIL_RemoveCallForwarding()
                case IOCTL_RIL_REMOVECALLFORWARDING:
                    CALLDRVAPI_PARAMS(REMOVECALLFORWARDING_PARAMS, RILDrv_RemoveCallForwarding(dwOpenData, \
                                                                                                            pParams->dwReason, pParams->dwInfoClasses));
                    break;

                    // RIL_SetCallForwardingStatus()
                case IOCTL_RIL_SETCALLFORWARDINGSTATUS:
                    CALLDRVAPI_PARAMS(SETCALLFORWARDINGSTATUS_PARAMS, RILDrv_SetCallForwardingStatus(dwOpenData, \
                                                                                                     pParams->dwReason, \
                                                                                                     pParams->dwInfoClasses, \
                                                                                                     pParams->dwStatus));
                    break;

                    // RIL_GetCallWaitingSettings()
                case IOCTL_RIL_GETCALLWAITINGSETTINGS:
                    CALLDRVAPI_PARAMS(GETCALLWAITINGSTATUS_PARAMS, RILDrv_GetCallWaitingSettings(dwOpenData, pParams->dwInfoClasses));
                    break;

                    // RIL_SetCallWaitingStatus()
                case IOCTL_RIL_SETCALLWAITINGSTATUS:
                    CALLDRVAPI_PARAMS(SETCALLWAITINGSTATUS_PARAMS, RILDrv_SetCallWaitingStatus(dwOpenData, \
                                                                                                            pParams->dwInfoClasses, pParams->dwStatus));
                    break;

                    // RIL_SendSupServiceData()
                case IOCTL_RIL_SENDSUPSERVICEDATA:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_SendSupServiceData(dwOpenData, pParams, dwLenIn));
                    break;

                    // RIL_CancelSupServiceDataSession()
                case IOCTL_RIL_CANCELSUPSERVICEDATASESSION:
                    CALLDRVAPI(RILDrv_CancelSupServiceDataSession);
                    break;

                    // RIL_GetCurrentAddressId()
                case IOCTL_RIL_GETCURRENTADDRESSID:
                    CALLDRVAPI(RILDrv_GetCurrentAddressId);
                    break;

                    // RIL_SetCurrentAddressId()
                case IOCTL_RIL_SETCURRENTADDRESSID:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetCurrentAddressId(dwOpenData, *pParams));
                    break;

                    // RIL_Dial()
                case IOCTL_RIL_DIAL:
                    CALLDRVAPI_PARAMS(DIAL_PARAMS, RILDrv_Dial(dwOpenData, pParams->szAddress, pParams->dwType, \
                                                                            pParams->dwOptions));
                    break;

                    // RIL_Asnwer()
                case IOCTL_RIL_ANSWER:
                    CALLDRVAPI(RILDrv_Answer);
                    break;

                    // RIL_Hangup()
                case IOCTL_RIL_HANGUP:
                    CALLDRVAPI(RILDrv_Hangup);
                    break;

                    // RIL_SendDTMF()
                case IOCTL_RIL_SENDDTMF:
                    CALLDRVAPI_ARRAY(SENDDTMF_PARAMS, RILDrv_SendDTMF(dwOpenData, pParams->szDTMF, pParams->dwDuration));
                    break;

                    // RIL_SetDTMFMonitoring()
                case IOCTL_RIL_SETDTMFMONITORING:
                    CALLDRVAPI_PARAMS(BOOL, RILDrv_SetDTMFMonitoring(dwOpenData, *pParams));
                    break;

                    // RIL_GetCallList()
                case IOCTL_RIL_GETCALLLIST:
                    CALLDRVAPI(RILDrv_GetCallList);
                    break;

                    // RIL_ManageCalls()
                case IOCTL_RIL_MANAGECALLS:
                    CALLDRVAPI_PARAMS(MANAGECALLS_PARAMS, RILDrv_ManageCalls(dwOpenData, pParams->dwCommand, pParams->dwID));
                    break;

                    // RIL_TransferCall()
                case IOCTL_RIL_TRANSFERCALL:
                    CALLDRVAPI_PARAMS(TRANSFERCALL_PARAMS, RILDrv_TransferCall(dwOpenData, &pParams->raAddress, \
                                                                                            (pParams->fSubAddress ? &pParams->rsaSubAddress : NULL)));
                    break;

                    // RIL_GetLineStatus()
                case IOCTL_RIL_GETLINESTATUS:
                    CALLDRVAPI(RILDrv_GetLineStatus);
                    break;

                    // RIL_GetAudioGain()
                case IOCTL_RIL_GETAUDIOGAIN:
                    CALLDRVAPI(RILDrv_GetAudioGain);
                    break;

                    // RIL_SetAudioGain()
                case IOCTL_RIL_SETAUDIOGAIN:
                    CALLDRVAPI_PARAMS(RILGAININFO, RILDrv_SetAudioGain(dwOpenData, pParams));
                    break;

                    // RIL_GetAudioDevices()
                case IOCTL_RIL_GETAUDIODEVICES:
                    CALLDRVAPI(RILDrv_GetAudioDevices);
                    break;

                    // RIL_SetAudioDevices()
                case IOCTL_RIL_SETAUDIODEVICES:
                    CALLDRVAPI_PARAMS(RILAUDIODEVICEINFO, RILDrv_SetAudioDevices(dwOpenData, pParams));
                    break;

                    // RIL_GetAudioMuting()
                case IOCTL_RIL_GETAUDIOMUTING:
                    CALLDRVAPI(RILDrv_GetAudioMuting);
                    break;

                    // RIL_SetAudioMuting()
                case IOCTL_RIL_SETAUDIOMUTING:
                    CALLDRVAPI_PARAMS(BOOL, RILDrv_SetAudioMuting(dwOpenData, *pParams));
                    break;

                    // RIL_GetHSCSDOptions()
                case IOCTL_RIL_GETHSCSDOPTIONS:
                    CALLDRVAPI(RILDrv_GetHSCSDOptions);
                    break;

                    // RIL_SetHSCSDOptions()
                case IOCTL_RIL_SETHSCSDOPTIONS:
                    CALLDRVAPI_PARAMS(RILHSCSDINFO, RILDrv_SetHSCSDOptions(dwOpenData, pParams));
                    break;

                    // RIL_GetHSCSDCallSettings()
                case IOCTL_RIL_GETHSCSDCALLSETTINGS:
                    CALLDRVAPI(RILDrv_GetHSCSDCallSettings);
                    break;

                    // RIL_GetDataCompression()
                case IOCTL_RIL_GETDATACOMPRESSION:
                    CALLDRVAPI(RILDrv_GetDataCompression);
                    break;

                    // RIL_SetDataCompression()
                case IOCTL_RIL_SETDATACOMPRESSION:
                    CALLDRVAPI_PARAMS(RILDATACOMPINFO, RILDrv_SetDataCompression(dwOpenData, pParams));
                    break;

                    // RIL_GetErrorCorrection()
                case IOCTL_RIL_GETERRORCORRECTION:
                    CALLDRVAPI(RILDrv_GetErrorCorrection);
                    break;

                    // RIL_SetErrorCorrection()
                case IOCTL_RIL_SETERRORCORRECTION:
                    CALLDRVAPI_PARAMS(RILERRORCORRECTIONINFO, RILDrv_SetErrorCorrection(dwOpenData, pParams));
                    break;

                    // RIL_GetBearerServiceOptions()
                case IOCTL_RIL_GETBEARERSERVICEOPTIONS:
                    CALLDRVAPI(RILDrv_GetBearerServiceOptions);
                    break;

                    // RIL_SetBearerServiceOptions()
                case IOCTL_RIL_SETBEARERSERVICEOPTIONS:
                    CALLDRVAPI_PARAMS(RILBEARERSVCINFO, RILDrv_SetBearerServiceOptions(dwOpenData, pParams));
                    break;

                    // RIL_GetRLPOptions()
                case IOCTL_RIL_GETRLPOPTIONS:
                    CALLDRVAPI(RILDrv_GetRLPOptions);
                    break;

                    // RIL_SetRLPOptions()
                case IOCTL_RIL_SETRLPOPTIONS:
                    CALLDRVAPI_PARAMS(RILRLPINFO, RILDrv_SetRLPOptions(dwOpenData, pParams));
                    break;

                    // RIL_GetMsgServiceOptions()
                case IOCTL_RIL_GETMSGSERVICEOPTIONS:
                    CALLDRVAPI(RILDrv_GetMsgServiceOptions);
                    break;

                    // RIL_SetMsgServiceOptions()
                case IOCTL_RIL_SETMSGSERVICEOPTIONS:
                    CALLDRVAPI_PARAMS(RILMSGSERVICEINFO, RILDrv_SetMsgServiceOptions(dwOpenData, pParams));
                    break;

                    // RIL_GetMsgConfig()
                case IOCTL_RIL_GETMSGCONFIG:
                    CALLDRVAPI(RILDrv_GetMsgConfig);
                    break;

                    // RIL_SetMsgConfig()
                case IOCTL_RIL_SETMSGCONFIG:
                    CALLDRVAPI_PARAMS(RILMSGCONFIG, RILDrv_SetMsgConfig(dwOpenData, pParams));
                    break;

                    // RIL_GetCellBroadcastMsgConfig()
                case IOCTL_RIL_GETCBMSGCONFIG:
                    CALLDRVAPI(RILDrv_GetCellBroadcastMsgConfig);
                    break;

                    // RIL_SetCellBroadcastMsgConfig()
                case IOCTL_RIL_SETCBMSGCONFIG:
                    CALLDRVAPI_OPTVARPARAMS(RILCBMSGCONFIG, RILDrv_SetCellBroadcastMsgConfig(dwOpenData, pParams));
                    break;

                    // RIL_ReadMsg()
                case IOCTL_RIL_READMSG:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_ReadMsg(dwOpenData, *pParams));
                    break;

                    // RIL_DeleteMsg()
                case IOCTL_RIL_DELETEMSG:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_DeleteMsg(dwOpenData, *pParams));
                    break;

                    // RIL_WriteMsg()
                case IOCTL_RIL_WRITEMSG:
                    CALLDRVAPI_PARAMS(WRITEMSG_PARAMS, RILDrv_WriteMsg(dwOpenData, &pParams->rmMessage, pParams->dwStatus));
                    break;

                    // RIL_SendMsg()
                case IOCTL_RIL_SENDMSG:
                    CALLDRVAPI_PARAMS(SENDMSG_PARAMS, RILDrv_SendMsg(dwOpenData, &pParams->rmMessage, pParams->dwOptions));
                    break;

                    // RIL_SendStoredMsg()
                case IOCTL_RIL_SENDSTOREDMSG:
                    CALLDRVAPI_PARAMS(SENDSTOREDMSG_PARAMS, RILDrv_SendStoredMsg(dwOpenData, pParams->dwIndex, \
                                                                                              pParams->dwOptions));
                    break;

                    // RIL_SendMsgAcknowledgement()
                case IOCTL_RIL_SENDMSGACKNOWLEDGEMENT:
                    CALLDRVAPI_PARAMS(BOOL, RILDrv_SendMsgAcknowledgement(dwOpenData, *pParams));
                    break;

                    // RIL_GetUserIdentity()
                case IOCTL_RIL_GETUSERIDENTITY:
                    CALLDRVAPI(RILDrv_GetUserIdentity);
                    break;

                    // RIL_GetUserIdentity()
                case IOCTL_RIL_GETPHONELOCKEDSTATE:
                    CALLDRVAPI(RILDrv_GetPhoneLockedState);
                    break;

                    // RIL_UnlockPhone()
                case IOCTL_RIL_UNLOCKPHONE:
                    CALLDRVAPI_PARAMS(UNLOCKPHONE_PARAMS, RILDrv_UnlockPhone(dwOpenData, pParams->szPassword, \
                                                                                          (pParams->fNewPassword ? pParams->szNewPassword : NULL)));
                    break;

                    // RIL_GetLockingStatus()
                case IOCTL_RIL_GETLOCKINGSTATUS:
                    CALLDRVAPI_PARAMS(GETLOCKINGSTATUS_PARAMS, RILDrv_GetLockingStatus(dwOpenData, pParams->dwFacility, \
                                                                                                    (pParams->fPassword ? pParams->szPassword : NULL)));
                    break;

                    // RIL_SetLockingStatus()
                case IOCTL_RIL_SETLOCKINGSTATUS:
                    CALLDRVAPI_PARAMS(SETLOCKINGSTATUS_PARAMS, RILDrv_SetLockingStatus(dwOpenData, pParams->dwFacility, \
                                                                                                    (pParams->fPassword ? pParams->szPassword: NULL), pParams->dwStatus));
                    break;

                    // RIL_ChangeLockingPassword()
                case IOCTL_RIL_CHANGELOCKINGPASSWORD:
                    CALLDRVAPI_PARAMS(CHANGELOCKINGPASSWORD_PARAMS, RILDrv_ChangeLockingPassword(dwOpenData, \
                                                                                                              pParams->dwFacility, pParams->dwOldPasswordType, pParams->szOldPassword, pParams->szNewPassword));
                    break;

                    // RIL_GetCallBarringStatus()
                case IOCTL_RIL_GETCALLBARRINGSTATUS:
                    CALLDRVAPI_PARAMS(GETCALLBARRINGSTATUS_PARAMS, RILDrv_GetCallBarringStatus(dwOpenData, \
                                                                                                            pParams->dwType, pParams->dwInfoClass, (pParams->fPassword ? pParams->szPassword : NULL)));
                    break;

                    // RIL_SetCallBarringStatus()
                case IOCTL_RIL_SETCALLBARRINGSTATUS:
                    CALLDRVAPI_PARAMS(SETCALLBARRINGSTATUS_PARAMS, RILDrv_SetCallBarringStatus(dwOpenData, \
                                                                                                            pParams->dwType, pParams->dwInfoClass, (pParams->fPassword ? pParams->szPassword : NULL), pParams->dwStatus));
                    break;

                    // RIL_ChangeCallBarringPassword()
                case IOCTL_RIL_CHANGECALLBARRINGPASSWORD:
                    CALLDRVAPI_PARAMS(CHANGECALLBARRINGPASSWORD_PARAMS, RILDrv_ChangeCallBarringPassword(dwOpenData, \
                                                                                                                      pParams->dwType, pParams->szOldPassword, pParams->szNewPassword));
                    break;

                    // RIL_GetEquipmentInfo()
                case IOCTL_RIL_GETEQUIPMENTINFO:
                    CALLDRVAPI(RILDrv_GetEquipmentInfo);
                    break;

                    // RIL_GetEquipmentState()
                case IOCTL_RIL_GETEQUIPMENTSTATE:
                    CALLDRVAPI(RILDrv_GetEquipmentState);
                    break;

                    // RIL_SetEquipmentState()
                case IOCTL_RIL_SETEQUIPMENTSTATE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetEquipmentState(dwOpenData, *pParams));
                    break;

                    // RIL_GetPhonebookOptions()
                case IOCTL_RIL_GETPHONEBOOKOPTIONS:
                    CALLDRVAPI(RILDrv_GetPhonebookOptions);
                    break;

                    // RIL_SetPhonebookOptions()
                case IOCTL_RIL_SETPHONEBOOKOPTIONS:
                    CALLDRVAPI_PARAMS(RILPHONEBOOKINFO, RILDrv_SetPhonebookOptions(dwOpenData, pParams));
                    break;

                    // RIL_ReadPhonebookEntries()
                case IOCTL_RIL_READPHONEBOOKENTRIES:
                    CALLDRVAPI_PARAMS(READPHONEBOOKENTRIES_PARAMS, RILDrv_ReadPhonebookEntries(dwOpenData, \
                                                                                                            pParams->dwStartIndex, pParams->dwEndIndex));
                    break;

                    // RIL_WritePhonebookEntry()
                case IOCTL_RIL_WRITEPHONEBOOKENTRY:
                    CALLDRVAPI_PARAMS(RILPHONEBOOKENTRY, RILDrv_WritePhonebookEntry(dwOpenData, pParams));
                    break;

                    // RIL_DeletePhonebookEntry()
                case IOCTL_RIL_DELETEPHONEBOOKENTRY:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_DeletePhonebookEntry(dwOpenData, *pParams));
                    break;

                    // RIL_SendSimCmd()
                case IOCTL_RIL_SENDSIMCMD:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_SendSimCmd(dwOpenData, pParams, dwLenIn));
                    break;

                    // RIL_SendRestrictedSimCmd()
                case IOCTL_RIL_SENDRESTRICTEDSIMCMD:
                    CALLDRVAPI_ARRAY(SENDRESTRICTEDSIMCMD_PARAMS, RILDrv_SendRestrictedSimCmd(dwOpenData, \
                                                                                                           pParams->dwCommand, &pParams->rscpParameters, pParams->pbData, \
                                                                                                           dwLenIn - sizeof(SENDRESTRICTEDSIMCMD_PARAMS)));
                    break;

                    // RIL_GetSimRecordStatus()
                case IOCTL_RIL_GETSIMRECORDSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetSimRecordStatus(dwOpenData, *pParams));
                    break;

                    // RIL_GetSimToolkitProfile()
                case IOCTL_RIL_GETSIMTOOLKITPROFILE:
                    CALLDRVAPI(RILDrv_GetSimToolkitProfile);
                    break;

                    // RIL_SetSimToolkitProfile()
                case IOCTL_RIL_SETSIMTOOLKITPROFILE:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_SetSimToolkitProfile(dwOpenData, pParams, dwLenIn));
                    break;

                    // RIL_FetchSimToolkitCmd()
                case IOCTL_RIL_FETCHSIMTOOLKITCMD:
                    CALLDRVAPI(RILDrv_FetchSimToolkitCmd);
                    break;

                    // RIL_TerminateSimToolkitSession()
                case IOCTL_RIL_TERMINATESIMTOOLKITSESSION:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_TerminateSimToolkitSession(dwOpenData, *pParams));
                    break;

#ifdef SIEMENS_MAGNETO
                    // RIL_SendSimToolkitCmdResponse()
                case IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE:
                    CALLDRVAPI_ARRAY(SENDSIMTOOLKITCMDRESPONSE_PARAMS, RILDrv_SendSimToolkitCmdResponse(dwOpenData,          \
                                                                                                        &pParams->rstrRsp,   \
                                                                                                        pParams->pbDetails,  \
                                                                                                        dwLenIn - sizeof(SENDSIMTOOLKITCMDRESPONSE_PARAMS)));
                    break;

                    // RIL_SendSimToolkitEventDownload()
                case IOCTL_RIL_SENDSIMTOOLKITEVENTDOWNLOAD:
                    CALLDRVAPI_ARRAY(SENDSIMTOOLKITEVENTDOWNLOAD_PARAMS, RILDrv_SendSimToolkitEventDownload(dwOpenData,       \
                                                                                                            pParams->dwEvent, \
                                                                                                            pParams->pbData,  \
                                                                                                            dwLenIn - sizeof(SENDSIMTOOLKITEVENTDOWNLOAD_PARAMS)));
                    break;

#else // SIEMENS_MAGNETO
                    // RIL_SendSimToolkitCmdResponse()
                case IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_SendSimToolkitCmdResponse(dwOpenData, pParams, dwLenIn));
                    break;

                    // RIL_SendSimToolkitEnvelopeCmd()
                case IOCTL_RIL_SENDSIMTOOLKITENVELOPECMD:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_SendSimToolkitEnvelopeCmd(dwOpenData, pParams, dwLenIn));
                    break;
#endif // SIEMENS_MAGNETO

                    // RIL_GetCostInfo()
                case IOCTL_RIL_GETCOSTINFO:
                    CALLDRVAPI(RILDrv_GetCostInfo);
                    break;

                    // RIL_SetCostInfo()
                case IOCTL_RIL_SETCOSTINFO:
                    CALLDRVAPI_PARAMS(SETCOSTINFO_PARAMS, RILDrv_SetCostInfo(dwOpenData, &pParams->rciCostInfo, \
                                                                                          (pParams->fPassword ? pParams->szPassword : NULL)));
                    break;

                    // RIL_GetSignalQuality()
                case IOCTL_RIL_GETSIGNALQUALITY:
                    CALLDRVAPI(RILDrv_GetSignalQuality);
                    break;

                    // RIL_GetCellTowerInfo()
                case IOCTL_RIL_GETCELLTOWERINFO:
                    CALLDRVAPI(RILDrv_GetCellTowerInfo);
                    break;
                    // RIL_DevSpecific()
                case IOCTL_RIL_DEVSPECIFIC:
                    CALLDRVAPI_ARRAY(BYTE, RILDrv_DevSpecific(dwOpenData, pParams, dwLenIn));
                    break;

                    // RIL_GetDevCaps()
                case IOCTL_RIL_GETDEVCAPS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetDevCaps(dwOpenData, *pParams));
                    break;

                    // RIL_GetCCBSStatus()
                case IOCTL_RIL_GETCCBSSTATUS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetCCBSStatus(dwOpenData, *pParams));
                    break;

                    // RIL_ClearCCBSRegistration()
                case IOCTL_RIL_CLEARCCBSREGISTRATION:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_ClearCCBSRegistration(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_GETSYSTEMTIME:
                    CALLDRVAPI(RILDrv_GetSystemTime);
                    break;

                
                /**********************************************************************************
 												GPRS IOCTRL  Start
                **********************************************************************************/
                case IOCTL_RIL_GETGPRSCONTEXTLIST: //Get the PDP context data 
                    CALLDRVAPI(RILDrv_GetGPRSContextList);
                    break;
                case IOCTL_RIL_SETGPRSCONTEXT:     //For PDP Context Define. 
                    CALLDRVAPI_VARPARAMS(RILGPRSCONTEXT, RILDrv_SetGPRSContext(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_DELETEGPRSCONTEXT:  //delete the PDP context data 
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_DeleteGPRSContext(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_GETREQUESTEDQUALITYOFSERVICELIST:
                    CALLDRVAPI(RILDrv_GetRequestedQualityOfServiceList);
                    break;
                case IOCTL_RIL_SETREQUESTEDQUALITYOFSERVICE:
                    CALLDRVAPI_PARAMS(RILGPRSQOSPROFILE, RILDrv_SetRequestedQualityOfService(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_DELETEREQUESTEDQUALITYOFSERVICE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_DeleteRequestedQualityOfService(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_GETMINIMUMQUALITYOFSERVICELIST:
                    CALLDRVAPI(RILDrv_GetMinimumQualityOfServiceList);
                    break;
                case IOCTL_RIL_SETMINIMUMQUALITYOFSERVICE:
                    CALLDRVAPI_PARAMS(RILGPRSQOSPROFILE, RILDrv_SetMinimumQualityOfService(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_DELETEMINIMUMQUALITYOFSERVICE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_DeleteMinimumQualityOfService(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_SETGPRSATTACHED:    //Attaced GPRS
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetGPRSAttached(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_GETGPRSATTACHED:    //Get GPRS attach status
                    CALLDRVAPI(RILDrv_GetGPRSAttached);
                    break;
                case IOCTL_RIL_SETGPRSCONTEXTACTIVATED:   //Activated/deactivated the correspondding context id
                    CALLDRVAPI_PARAMS(SETGPRSCONTEXTACTIVATED_PARAMS, RILDrv_SetGPRSContextActivated(dwOpenData, pParams->dwContextID, pParams->fContextActivation));
                    break;
                case IOCTL_RIL_GETGPRSCONTEXTACTIVATEDLIST:
                    CALLDRVAPI(RILDrv_GetGPRSContextActivatedList);
                    break;
                case IOCTL_RIL_ENTERGPRSDATAMODE:
                    CALLDRVAPI_OPTVARPARAMS(RILENTERGPRSDATAMODE, RILDrv_EnterGPRSDataMode(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_GETGPRSADDRESS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_GetGPRSAddress(dwOpenData, *pParams));
                    break;
                case IOCTL_RIL_GPRSANSWER:
                    CALLDRVAPI_VARPARAMS(RILGPRSANSWER, RILDrv_GPRSAnswer(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_GETGPRSREGISTRATIONSTATUS:
                    CALLDRVAPI(RILDrv_GetGPRSRegistrationStatus);
                    break;
                case IOCTL_RIL_GETGPRSCLASS:
                    CALLDRVAPI(RILDrv_GetGPRSClass);
                    break;
                case IOCTL_RIL_SETGPRSCLASS:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetGPRSClass(dwOpenData, *pParams));
                    break;

                /**********************************************************************************
                                            GPRS IOCTRL  End
                **********************************************************************************/
                case IOCTL_RIL_GETMOSMSSERVICE:
                    CALLDRVAPI(RILDrv_GetMOSMSService);
                    break;
                case IOCTL_RIL_SETMOSMSSERVICE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetMOSMSService(dwOpenData, *pParams));
                    break;
#ifdef SIEMENS_MAGNETO
                case IOCTL_RIL_NDIS_RECEIVEPACKETDONE:
                    CALLDRVAPI_VARPARAMS(RILNDISPACKET, RILDrv_NdisReceivePacketDone(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_NDIS_SENDPACKET:
                    CALLDRVAPI_VARPARAMS(RILNDISPACKET, RILDrv_NdisSendPacket(dwOpenData, pParams));
                    break;
                case IOCTL_RIL_NDIS_SETGPRSCONTEXTACTIVATED:
                    CALLDRVAPI_PARAMS(RILNDISSETGPRSCONTEXTACTIVATED, RILDrv_NdisSetGPRSContextActivated(dwOpenData, pParams));
                    break;
#endif

                // CDMA functions
                case IOCTL_RIL_GETPACKETBYTECOUNT:
                    CALLDRVAPI(RILDrv_GetPacketByteCount);
                    break;

                case IOCTL_RIL_RESETPACKETBYTECOUNT:
                    CALLDRVAPI(RILDrv_ResetPacketByteCount);
                    break;

                case IOCTL_RIL_GETCURRENTSYSTEMTYPE:
                    CALLDRVAPI(RILDrv_GetCurrentSystemType);
                    break;

                case IOCTL_RIL_SENDFLASH:
                    CALLDRVAPI_PARAMS(RILADDRESS, RILDrv_SendFlash(dwOpenData, *pParams));
                    break;

                case IOCTL_RIL_GETROAMINGMODE:
                    CALLDRVAPI(RILDrv_GetRoamingMode);
                    break;

                case IOCTL_RIL_SETROAMINGMODE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetRoamingMode(dwOpenData, *pParams));
                    break;

                case IOCTL_RIL_GETPREFERREDPRIVACYMODE:
                    CALLDRVAPI(RILDrv_GetPreferredPrivacyMode);
                    break;

                case IOCTL_RIL_SETPREFERREDPRIVACYMODE:
                    CALLDRVAPI_PARAMS(DWORD, RILDrv_SetPreferredPrivacyMode(dwOpenData, *pParams));
                    break;

                case IOCTL_RIL_GETCURRENTPRIVACYSTATUS:
                    CALLDRVAPI(RILDrv_GetCurrentPrivacyStatus);
                    break;

#ifdef SIEMENS_MAGNETO
                case IOCTL_RIL_GETCURRENTLOCATIONSTATUS:
                    CALLDRVAPI(RILDrv_GetCurrentLocationStatus);
                    break;

                case IOCTL_RIL_GETCURRENTROAMINGSTATUS:
                    CALLDRVAPI(RILDrv_GetCurrentRoamingStatus);
                    break;

                case IOCTL_RIL_SENDAKEY:
                    // parameters to SendAKey are a little wierd, so there isn't a suitable macro yet.
                    *phr = RILDrv_SendAKey(dwOpenData, (LPCSTR)pBufIn);
                    dwOutUsed = sizeof(HRESULT);
                    fRet = TRUE;
                    break;

                case IOCTL_RIL_GETATR:
                    CALLDRVAPI(RILDrv_GetATR);
                    break;

#else
                case IOCTL_RIL_SENDAKEY:
                    CALLDRVAPI(RILDrv_SendAKey);
                    break;
#endif

//////////////////////////////////////////////////////////////////////////////
//
// Microsoft Automotive
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// These definitions are used for the antenna diagnostic extension:
//
// #define RIL_ANTENNASTATUS_UNKNOWN        (0x00000000)  // @constdefine Unknown status
// #define RIL_ANTENNASTATUS_CONNECTED      (0x00000001)  // @constdefine Antenna connected
// #define RIL_ANTENNASTATUS_DISCONNECTED   (0x00000002)  // @constdefine Antenna disconnected
// #define RIL_ANTENNASTATUS_SHORTED        (0x00000003)  // @constdefine
// #define RIL_ANTENNASTATUS_SHORTEDGROUND  (0x00000004)  // @constdefine
//
// #define IOCTL_RIL_GETANTENNASTATUS       CTL_CODE(FILE_DEVICE_RIL, 166, METHOD_BUFFERED, FILE_ANY_ACCESS)
//
//////////////////////////////////////////////////////////////////////////////
#ifdef IOCTL_RIL_GETANTENNASTATUS
                case IOCTL_RIL_GETANTENNASTATUS:
                    CALLDRVAPI(RILDrv_GetAntennaStatus)
                    break;
#endif // IOCTL_RIL_GETANTENNASTATUS

//////////////////////////////////////////////////////////////////////////////
// These definitions are used for the Remote SIM Access extension:
//
// typedef struct rilentersapmode_tag {
//   DWORD cbSize;           // @field struct size in bytes
//   DWORD dwSAPMode;        // @field device sap mode (RIL_SAPMODE_*)
//   DWORD dwDataMode;       // @field data format to be used (RIL_SAPDATAMODE_*)
//   BOOL  bAutoReconnect;   // @field whether disconnection requests or unsuccessful
//                           //        connection requests are followed by additional
//                           //        connection requests
// } RILENTERSAPMODE, *LPRILENTERSAPMODE;
//
// #define RIL_SAPMODE_CLIENT    (0x00000000)      // @constdefine client mode
// #define RIL_SAPMODE_SERVER    (0x00000001)      // @constdefine server mode
// #define RIL_SAPDATAMODE_SAP   (0x00000000)      // @constdefine binary mode
// #define RIL_SAPDATAMODE_XSAP  (0x00000001)
//
// HRESULT RILDrv_EnterSAPMode(DWORD dwHandle, LPRILENTERSAPMODE lpEnterSapMode);
// HRESULT RILDrv_ExitSAPMode(DWORD dwHandle, BOOL bForce);
//
//////////////////////////////////////////////////////////////////////////////
#ifdef SAP_SUPPORTED
                case IOCTL_RIL_GETSERIALPORTHANDLEFORSAP:
                    {
                        TCHAR* szPort = g_ComManager.GetPortName(g_ComManager.GetRsaPort());
                        if (szPort)
                        {
                            if ((_tcslen(szPort) + 1) < dwLenOut)
                            {
                                _tcscpy((TCHAR*)pBufOut, szPort);
                                dwOutUsed = _tcslen((TCHAR*)pBufOut);
                                fRet = TRUE;
                            }
                        }
                        break;
                    }

                case IOCTL_RIL_ENTERSAPMODE:
                    {
                        CALLDRVAPI_PARAMS(RILENTERSAPMODE, RILDrv_EnterSAPMode(dwOpenData, pParams));
                    }

                case IOCTL_RIL_EXITSAPMODE:
                    {
                        CALLDRVAPI_PARAMS(BOOL, RILDrv_ExitSAPMode(dwOpenData, *pParams));
                    }
#endif // SAP_SUPPORTED

//////////////////////////////////////////////////////////////////////////////
//
// End of Microsoft Automotive
//
//////////////////////////////////////////////////////////////////////////////
                }
                break;
            }
        }
    }

    if (pdwActualOut)
    {
        *pdwActualOut = dwOutUsed;
    }

    Error:
    return fRet;
}

//
//
//
HRESULT RILDrv_GetNextNotification(DWORD dwParam, RILDRVNOTIFICATION* lpRilDrvNotification)
{
    //TBD_FUNCTION(RILDrv_GetNextNotification);
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam, TRUE);
    if (!pHandle)
    {
        hr = E_INVALIDARG;
        goto Error;
    }

    if (!pHandle->GetNextNotification(*lpRilDrvNotification))
    {
        hr = E_FAIL;
    }

    Error:
    return hr;
}


//
//
//
HRESULT RILDrv_GetSerialPortStatistics(DWORD dwParam, RILSERIALPORTSTATS* lpSerialPortStats)
{
    TBD_FUNCTION(RILDrv_GetSerialPortStatistics);
    HRESULT hr = S_OK;
    CRilHandle* pRilDevice;
    CComHandle* pComDevice;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle)
    {
        hr = E_INVALIDARG;
        goto Error;
    }

    pRilDevice = pHandle->GetDevice();
    TBD_ASSERT(NULL != pRilDevice);

    pComDevice = pRilDevice->GetComDevice(COMMAND_PORT);
    TBD_ASSERT(NULL != pComDevice);

    pComDevice->CalculateComStats(lpSerialPortStats->dwReadBitsPerSecond, lpSerialPortStats->dwWrittenBitsPerSecond);
    lpSerialPortStats->dwParams = RIL_PARAM_SPS_ALL;

    Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SetPowerState(DWORD dwParam, CEDEVICE_POWER_STATE PowerState)
{
  TBD_FUNCTION(RILDrv_SetPowerState);
  CRilInstanceHandle* pHandle = ExtractHandle(dwParam);

  if (!pHandle) {
    return E_INVALIDARG;
  } else {
    if (g_PowerManager.EnterPowerState(pHandle, PowerState)) {
      return S_OK;
    }
  }
  return E_FAIL;
}


//
// Function passed to CQueue::Enum() above
//
BOOL ClearCmdHandle(void* pItem, DWORD dwDummy)
{
    TBD_FUNCTION(ClearCmdHandle);
    TBD_ASSERT(pItem != NULL);

    CCommand* pCmd = (CCommand*)pItem;
    pCmd->ClearHandle();

    // Continue enumeration
    return FALSE;
}


//
//
//
CRilInstanceHandle* const ExtractHandle(const DWORD dwParam, BOOL bOverrideEmergency)
{
    //TBD_FUNCTION(ExtractHandle);
    CRilInstanceHandle* pRet;
    CRilHandle* pRilDevice;

    // Cast the DWORD into a handle
    pRet = (CRilInstanceHandle*)dwParam;
    if (!pRet)
    {
        goto Error;
    }

    pRilDevice = pRet->GetDevice();
    TBD_ASSERT(NULL != pRilDevice);

    // If we're in emergency mode, make sure this is a preferred handle
    if ((!bOverrideEmergency) && pRilDevice->FInEmergencyMode() && !pRet->FPreferred())
    {
        pRet = NULL;
        goto Error;
    }

    Error:
    return pRet;
}


//
//
//
DWORD g_SignalCriticalErrorEventId=0;

void SignalCriticalError(DWORD dwEventId)
{
    TBD_FUNCTION(SignalCriticalError);
    g_SignalCriticalErrorEventId=dwEventId;
    TBD_OUTPUT(TBDCT_INFO, TBDOL_ERROR, TEXT("SignalCriticalError : error = %x"), dwEventId);
    RILRetailTrace((TEXT("RilDrv: SignalCriticalError : error = %x"), dwEventId));
    g_RilLog.LogEvent(RILLOG_ZONE_ERROR, dwEventId);
    (void)SetEvent(g_hCriticalErrorEvent);
}

VOID RIL_PrintIoCtrlCode(DWORD dwCode)
{
    switch (dwCode)
    {
    case IOCTL_POWER_CAPABILITIES:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_POWER_CAPABILITIES)\n"), dwCode));            
        break;

    case IOCTL_POWER_GET:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_POWER_GET)\n"), dwCode));            
        break;

    case IOCTL_POWER_SET:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_POWER_SET)\n"), dwCode));            
        break;

    case IOCTL_CARKIT_ADD_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_CARKIT_ADD_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_CARKIT_REMOVE_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_CARKIT_REMOVE_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_HEADSET_ADD_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_HEADSET_ADD_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_HEADSET_REMOVE_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_HEADSET_REMOVE_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_SPEAKER_ADD_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_SPEAKER_ADD_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_SPEAKER_REMOVE_NOTIFY_HWND:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_SPEAKER_REMOVE_NOTIFY_HWND)\n"), dwCode));            
        break;

    case IOCTL_RIL_REGISTERWITHCPM:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_REGISTERWITHCPM)\n"), dwCode));            
        break;

    case IOCTL_RIL_EMERGENCYSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_EMERGENCYSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_INITNOTIFICATIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_INITNOTIFICATIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETNEXTNOTIFICATION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETNEXTNOTIFICATION)\n"), dwCode));            
        break;


    case IOCTL_RIL_GETSERIALPORTSTATISTICS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSERIALPORTSTATISTICS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETDRIVERVERSION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETDRIVERVERSION)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETLASTERROR:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETLASTERROR)\n"), dwCode));            
        break;

    case IOCTL_PSL_NOTIFY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_PSL_NOTIFY)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETSERIALPORTHANDLEFROMCONTEXTID:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSERIALPORTHANDLEFROMCONTEXTID)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETSUBSCRIBERNUMBERS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSUBSCRIBERNUMBERS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETOPERATORLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETOPERATORLIST)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETPREFERREDOPERATORLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETPREFERREDOPERATORLIST)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_ADDPREFERREDOPERATOR:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_ADDPREFERREDOPERATOR)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_REMOVEPREFERREDOPERATOR:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_REMOVEPREFERREDOPERATOR)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCURRENTOPERATOR:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTOPERATOR)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETALLOPERATORSLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETALLOPERATORSLIST)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_REGISTERONNETWORK:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_REGISTERONNETWORK)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_UNREGISTERFROMNETWORK:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_UNREGISTERFROMNETWORK)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETREGISTRATIONSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETREGISTRATIONSTATUS)\n"), dwCode));            
        break;
    case IOCTL_RIL_GETCALLERIDSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCALLERIDSETTINGS)\n"), dwCode));            
        break;
       
    case IOCTL_RIL_SETCALLERIDSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCALLERIDSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETHIDEIDSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETHIDEIDSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETHIDEIDSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETHIDEIDSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETDIALEDIDSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETDIALEDIDSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETDIALEDIDSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETDIALEDIDSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETHIDECONNECTEDIDSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETHIDECONNECTEDIDSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETHIDECONNECTEDIDSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETHIDECONNECTEDIDSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCLOSEDGROUPSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCLOSEDGROUPSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETCLOSEDGROUPSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCLOSEDGROUPSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCALLFORWARDINGSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCALLFORWARDINGSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_ADDCALLFORWARDING:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_ADDCALLFORWARDING)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_REMOVECALLFORWARDING:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_REMOVECALLFORWARDING)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETCALLFORWARDINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCALLFORWARDINGSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCALLWAITINGSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCALLWAITINGSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETCALLWAITINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCALLWAITINGSTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SENDSUPSERVICEDATA:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSUPSERVICEDATA)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_CANCELSUPSERVICEDATASESSION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_CANCELSUPSERVICEDATASESSION)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCURRENTADDRESSID:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTADDRESSID)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETCURRENTADDRESSID:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCURRENTADDRESSID)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_DIAL:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DIAL)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_ANSWER:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_ANSWER)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_HANGUP:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_HANGUP)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SENDDTMF:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDDTMF)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETDTMFMONITORING:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETDTMFMONITORING)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETCALLLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCALLLIST)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_MANAGECALLS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_MANAGECALLS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_TRANSFERCALL:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_TRANSFERCALL)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETLINESTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETLINESTATUS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETAUDIOGAIN:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETAUDIOGAIN)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETAUDIOGAIN:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETAUDIOGAIN)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETAUDIODEVICES:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETAUDIODEVICES)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETAUDIODEVICES:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETAUDIODEVICES)\n"), dwCode));            
        break;        
        
    case IOCTL_RIL_GETAUDIOMUTING:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETAUDIOMUTING)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETAUDIOMUTING:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETAUDIOMUTING)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETHSCSDOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETHSCSDOPTIONS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETHSCSDOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETHSCSDOPTIONS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETHSCSDCALLSETTINGS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETHSCSDCALLSETTINGS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETDATACOMPRESSION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETDATACOMPRESSION)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETDATACOMPRESSION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETDATACOMPRESSION)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETERRORCORRECTION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETERRORCORRECTION)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETERRORCORRECTION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETERRORCORRECTION)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETBEARERSERVICEOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETBEARERSERVICEOPTIONS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_SETBEARERSERVICEOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETBEARERSERVICEOPTIONS)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETRLPOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETRLPOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETRLPOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETRLPOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETMSGSERVICEOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETMSGSERVICEOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETMSGSERVICEOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETMSGSERVICEOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETMSGCONFIG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETMSGCONFIG)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETMSGCONFIG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETMSGCONFIG)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCBMSGCONFIG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCBMSGCONFIG)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETCBMSGCONFIG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCBMSGCONFIG)\n"), dwCode));            
        break;

    case IOCTL_RIL_READMSG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_READMSG)\n"), dwCode));            
        break;

    case IOCTL_RIL_DELETEMSG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DELETEMSG)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_WRITEMSG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_WRITEMSG)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDMSG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDMSG)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDSTOREDMSG:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSTOREDMSG)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDMSGACKNOWLEDGEMENT:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDMSGACKNOWLEDGEMENT)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETUSERIDENTITY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETUSERIDENTITY)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETPHONELOCKEDSTATE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETPHONELOCKEDSTATE)\n"), dwCode));            
        break;

    case IOCTL_RIL_UNLOCKPHONE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_UNLOCKPHONE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETLOCKINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETLOCKINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETLOCKINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETLOCKINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_CHANGELOCKINGPASSWORD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_CHANGELOCKINGPASSWORD)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCALLBARRINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCALLBARRINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETCALLBARRINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCALLBARRINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_CHANGECALLBARRINGPASSWORD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_CHANGECALLBARRINGPASSWORD)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETEQUIPMENTINFO:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETEQUIPMENTINFO)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETEQUIPMENTSTATE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETEQUIPMENTSTATE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETEQUIPMENTSTATE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETEQUIPMENTSTATE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETPHONEBOOKOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETPHONEBOOKOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETPHONEBOOKOPTIONS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETPHONEBOOKOPTIONS)\n"), dwCode));            
        break;

    case IOCTL_RIL_READPHONEBOOKENTRIES:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETLOCKINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_WRITEPHONEBOOKENTRY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_WRITEPHONEBOOKENTRY)\n"), dwCode));            
        break;

    case IOCTL_RIL_DELETEPHONEBOOKENTRY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DELETEPHONEBOOKENTRY)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDSIMCMD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSIMCMD)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDRESTRICTEDSIMCMD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDRESTRICTEDSIMCMD)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETSIMRECORDSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSIMRECORDSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETSIMTOOLKITPROFILE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSIMTOOLKITPROFILE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETSIMTOOLKITPROFILE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETSIMTOOLKITPROFILE)\n"), dwCode));            
        break;

    case IOCTL_RIL_FETCHSIMTOOLKITCMD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_FETCHSIMTOOLKITCMD)\n"), dwCode));            
        break;

    case IOCTL_RIL_TERMINATESIMTOOLKITSESSION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_TERMINATESIMTOOLKITSESSION)\n"), dwCode));            
        break;

#ifdef SIEMENS_MAGNETO
    case IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDSIMTOOLKITEVENTDOWNLOAD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSIMTOOLKITEVENTDOWNLOAD)\n"), dwCode));            
        break;
#else
    case IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSIMTOOLKITCMDRESPONSE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDSIMTOOLKITENVELOPECMD:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDSIMTOOLKITENVELOPECMD)\n"), dwCode));            
        break;
#endif

    case IOCTL_RIL_GETCOSTINFO:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCOSTINFO)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETCOSTINFO:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETCOSTINFO)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETSIGNALQUALITY:
        //RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSIGNALQUALITY)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCELLTOWERINFO:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCELLTOWERINFO)\n"), dwCode));            
        break;

    case IOCTL_RIL_DEVSPECIFIC:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DEVSPECIFIC)\n"), dwCode));            
        break;
        
    case IOCTL_RIL_GETDEVCAPS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETDEVCAPS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCCBSSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCCBSSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_CLEARCCBSREGISTRATION:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_CLEARCCBSREGISTRATION)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETSYSTEMTIME:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSYSTEMTIME)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSCONTEXTLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSCONTEXTLIST)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETGPRSCONTEXT:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETGPRSCONTEXT)\n"), dwCode));            
        break;

    case IOCTL_RIL_DELETEGPRSCONTEXT:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DELETEGPRSCONTEXT)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETREQUESTEDQUALITYOFSERVICELIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETREQUESTEDQUALITYOFSERVICELIST)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETREQUESTEDQUALITYOFSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETREQUESTEDQUALITYOFSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_DELETEREQUESTEDQUALITYOFSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DELETEREQUESTEDQUALITYOFSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETMINIMUMQUALITYOFSERVICELIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETMINIMUMQUALITYOFSERVICELIST)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETMINIMUMQUALITYOFSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETMINIMUMQUALITYOFSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_DELETEMINIMUMQUALITYOFSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_DELETEMINIMUMQUALITYOFSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETGPRSATTACHED:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETGPRSATTACHED)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSATTACHED:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSATTACHED)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETGPRSCONTEXTACTIVATED:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETGPRSCONTEXTACTIVATED)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSCONTEXTACTIVATEDLIST:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSCONTEXTACTIVATEDLIST)\n"), dwCode));            
        break;

    case IOCTL_RIL_ENTERGPRSDATAMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_ENTERGPRSDATAMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSADDRESS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSADDRESS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GPRSANSWER:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GPRSANSWER)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSREGISTRATIONSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSREGISTRATIONSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETGPRSCLASS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETGPRSCLASS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETGPRSCLASS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETGPRSCLASS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETMOSMSSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETMOSMSSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETMOSMSSERVICE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETMOSMSSERVICE)\n"), dwCode));            
        break;

    case IOCTL_RIL_NDIS_RECEIVEPACKETDONE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_NDIS_RECEIVEPACKETDONE)\n"), dwCode));            
        break;

    case IOCTL_RIL_NDIS_SENDPACKET:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_NDIS_SENDPACKET)\n"), dwCode));            
        break;

    case IOCTL_RIL_NDIS_SETGPRSCONTEXTACTIVATED:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_NDIS_SETGPRSCONTEXTACTIVATED)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETPACKETBYTECOUNT:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETPACKETBYTECOUNT)\n"), dwCode));            
        break;

    case IOCTL_RIL_RESETPACKETBYTECOUNT:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_RESETPACKETBYTECOUNT)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCURRENTSYSTEMTYPE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTSYSTEMTYPE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDFLASH:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDFLASH)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETROAMINGMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETROAMINGMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETROAMINGMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETROAMINGMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETPREFERREDPRIVACYMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETPREFERREDPRIVACYMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_SETPREFERREDPRIVACYMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SETPREFERREDPRIVACYMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCURRENTPRIVACYSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTPRIVACYSTATUS)\n"), dwCode));            
        break;
        
#ifdef SIEMENS_MAGNETO
    case IOCTL_RIL_GETCURRENTLOCATIONSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTLOCATIONSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETCURRENTROAMINGSTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETCURRENTROAMINGSTATUS)\n"), dwCode));            
        break;

    case IOCTL_RIL_SENDAKEY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDAKEY)\n"), dwCode));            
        break;

    case IOCTL_RIL_GETATR:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETATR)\n"), dwCode));            
        break;
#else
    case IOCTL_RIL_SENDAKEY:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_SENDAKEY)\n"), dwCode));            
        break;
#endif

#ifdef IOCTL_RIL_GETANTENNASTATUS
    case IOCTL_RIL_GETANTENNASTATUS:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETANTENNASTATUS)\n"), dwCode));            
        break;
#endif

#ifdef SAP_SUPPORTED
    case IOCTL_RIL_GETSERIALPORTHANDLEFORSAP:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_GETSERIALPORTHANDLEFORSAP)\n"), dwCode));            
        break;

    case IOCTL_RIL_ENTERSAPMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_ENTERSAPMODE)\n"), dwCode));            
        break;

    case IOCTL_RIL_EXITSAPMODE:
        RILRetailTrace((TEXT("RIL_IOControl %d (IOCTL_RIL_EXITSAPMODE)\n"), dwCode));            
        break;
#endif

    default:
        RILRetailTrace((TEXT("RIL_IOControl dwCode Error \n"), dwCode));            
        break;

    }
    
    return;
}
